from googlevoice import Voice,util

voice = Voice()
voice.login()
searchterm = util.input('Search query: ')

# print all pages of results, oldest to newest
page = 1
folder = voice.search(searchterm)
util.print_('Found %s messages: ' % len(folder))
while len(folder.messages) > 0:
	for msg in sorted(folder.messages, key = lambda m: m.startTime, reverse=True):
		util.print_('%s %s' % (msg.displayStartDateTime, msg.phoneNumber))
	page += 1
	folder = voice.search(searchterm, page)
